package bio.server;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Huhailong
 * @Description 时间服务器处理类线程池
 * @Date 2021/4/9.
 */
public class TimeServerHandlerThreadPool {
    private final ExecutorService executorService;

    /**
     * 构造方法
     *
     * @param maxPoolSize 线程池最大数量
     * @param queueSize   队列最大数量
     */
    public TimeServerHandlerThreadPool(int maxPoolSize, int queueSize) {
        int corePoolSize = Runtime.getRuntime().availableProcessors();
        if(corePoolSize>maxPoolSize) maxPoolSize = corePoolSize;
        executorService = new ThreadPoolExecutor(corePoolSize, maxPoolSize,
                120L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(queueSize));
    }

    public void execute(Runnable task){
        executorService.execute(task);
    }
}
